//
//  NSAttributedString+CrazyChatEmojiExtension.m
//  webSocket
//
//  Created by 马军凯 on 2019/1/25.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "NSAttributedString+CrazyChatEmojiExtension.h"
#import "CrazyChatExpressionText.h"

@implementation NSAttributedString (CrazyChatEmojiExtension)

//表情转字符串
- (NSMutableString *)getPlainString {
    NSMutableString *plainStr = [NSMutableString stringWithString:self.string];
    __block NSUInteger base = 0;
    
    [self enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, self.length) options:0 usingBlock:^(id  _Nullable value, NSRange range, BOOL * _Nonnull stop) {
        if (value && [value isKindOfClass:[CrazyChatExpressionText class]]) {
            [plainStr replaceCharactersInRange:NSMakeRange(range.location + base, range.length) withString:((CrazyChatExpressionText *)value).Tag];
            base += ((CrazyChatExpressionText *)value).Tag.length - 1;
        }
    }];
    
    return plainStr;
}





@end
